package com.imooc.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * MqReceiver
 *
 * @author leon.cheng
 * @date 2018/12/11 15:41
 **/
@Slf4j
@Component
public class MqReceiver {
    //@RabbitListener(queues = "myQueue")
   // 自动创建队列@RabbitListener(queuesToDeclare = @Queue("myQueue"))
    //自动创建，Exchange和Queue绑定
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange =@Exchange("myExchange")
    ))
    public void process(String message)
    {
        log.info("MyReceiver:{}",message);
    }

    /**
     * 数码供应商服务接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("computerOrder"),
            exchange =@Exchange("myOrder"),
            key = "computer"
    ))
    public void processComputer(String message)
    {
        log.info("computer MyReceiver:{}",message);
    }

    /**
     * 水果供应商服务接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("fruitOrder"),
            exchange =@Exchange("myOrder"),
            key = "fruit"
    ))
    public void processFruit(String message)
    {
        log.info("fruit MyReceiver:{}",message);
    }
}
